/*
 * This file is an example of how to embed web-server functionality
 * into existing application.
 * Compilation line:
 * cc example.c shttpd.c -DEMBEDDED
 */

#ifdef _WIN32
#include <winsock.h>
#define	snprintf			_snprintf
#pragma comment(lib,"ws2_32")
#else
#include <sys/types.h>
#include <sys/select.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <signal.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

extern int SendSMS(int fd, char *to, char *text);
static int gsm_modem = -1;
static int
send_sms (const char *phone, const char *text)
{
    return SendSMS(gsm_modem, phone, text);	
    return -1;
}

int
main (int argc, char *argv[])
{
  if(argc < 3){
    printf("Need to supply arguments in correct format\n");
	printf("%s phonenumber \"textmessage\"\n",argv[0]);
	return 0;
  }
  const char* phone_num = NULL;
  const char* text = NULL;
  
	phone_num = argv[1];
    text = argv[2];
	//int i=0;
	//while(text[i] != '\0')
	//{
	//	printf("%s\n",text);
	//	i++;
	//}
	//printf("%s\n",phone_num);
	//printf("%s\n",text);
  
  //printf("Hello World\n");
  int ret = 0;
  
  if(phone_num != NULL && text != NULL)
  {   
    if ((ret = send_sms (phone_num, text)) < 0) {
	printf("Could not Send Text\n");
	return -1;
	}
	else {
		  printf("Send message...OK\n");
	return 0;
	}
	}
	  if(gsm_modem > 0)
	close(gsm_modem);
	
	return 0;
}

